package com.yangwudongxi.sqlloghelper.dto;

import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * ER图生成请求
 *
 * @author 氧屋东西
 */
@Data
public class ErDiagramRequest {
    
    @NotNull(message = "ER图数据不能为空")
    private ErData erData;
    
    @NotNull(message = "数据库配置不能为空")
    @Valid
    private DatabaseConfig dbConfig;
    
    @Data
    public static class ErData {
        private java.util.List<SqlStatement> sqlStatements;
        private java.util.List<QueryResult> queryResults;
        private java.util.Map<String, TableInfo> tableInfo;
    }
    
    @Data
    public static class SqlStatement {
        private String sql;
        private String type;
        private java.util.List<String> tables;
    }
    
    @Data
    public static class QueryResult {
        private String sql;
        private String type;
        private ResultData result;
    }
    
    @Data
    public static class ResultData {
        private java.util.List<ColumnInfo> columns;
        private java.util.List<java.util.Map<String, Object>> rows;
        private Integer total;
        private Boolean hasMore;
    }
    
    @Data
    public static class ColumnInfo {
        private String name;
        private String comment;
        private String dataType;
    }
    
    @Data
    public static class TableInfo {
        private Integer count;
        private String comment;
        private Boolean loading;
        private String error;
    }
}